package com.fmdj.mps.controller;
import com.fmdj.common.util.CommonResult;
import com.fmdj.mps.controller.form.CalculateDriveLineForm;
import com.fmdj.mps.controller.form.CalculateTripDistanceAndDurationForm;
import com.fmdj.mps.controller.form.EstimateOrderMileageAndMinuteForm;
import com.fmdj.mps.service.CalculateTripDistanceAndDurationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/map")
@Tag(name = "MapController", description = "地图Web接口")
public class MapController {

    @Autowired
    private CalculateTripDistanceAndDurationService calculateTripDistanceAndDurationService;
    @PostMapping("/calculateTripDistanceAndDuration")
    @Operation(summary = "估算距离以及时间")
    public CommonResult calculateTripDistanceAndDuration(@Valid @RequestBody CalculateTripDistanceAndDurationForm form) {
        HashMap resultMap =  calculateTripDistanceAndDurationService.calculateTripDistanceAndDuration(form.getMode(), form.getStartPlaceLatitude(), form.getStartPlaceLongitude(), form.getEndPlaceLatitude(), form.getEndPlaceLongitude());
        return CommonResult.ok().put(CommonResult.RETURN_RESULT, resultMap);
    }

    @PostMapping("/calculateBestDrivingLine")
    @Operation(summary = "估算最佳行驶路线")
    public CommonResult calculateBestDrivingLine(@Valid @RequestBody CalculateDriveLineForm form) {
        HashMap result = calculateTripDistanceAndDurationService.calculateBestDrivingLine(form.getStartPlaceLatitude(), form.getStartPlaceLongitude(), form.getEndPlaceLatitude(), form.getEndPlaceLongitude());
        return CommonResult.ok().put(CommonResult.RETURN_RESULT, result);
    }
}
